#! /usr/bin/env python
# -*- coding: utf-8 -*-

# @author: xmj
# @date: 2023/5/6

from common.get_path import *
from common.utils import *
from jinja2 import Environment, FileSystemLoader


def create_html_report(**kwargs):
    """
    用于生产html格式的扫描报告
    :param kwargs: 所有模板中定义好的变量
    :return:
    """
    env = Environment(loader=FileSystemLoader(template_path))
    template = env.get_template("report_scan.html")
    # 此处打开文件需要指定编码为utf-8，否则生产报告中的中文会是乱码
    with open(report_path + "\\report-" + kwargs['report_time'] + ".html", "w+", encoding='utf-8') as f:
        # 传入模板已经定义好的变量
        html_content = template.render(
            total_num=kwargs['total_num'],
            success_num=kwargs['success_num'],
            fail_num=kwargs['fail_num'],
            start_time=kwargs['start_time'],
            end_time=kwargs['end_time'],
            interval=kwargs['interval'],
            is_auth=kwargs['is_auth'],
            fail_list=kwargs['fail_list'],
            pass_list=kwargs['pass_list']
        )
        f.write(html_content)
